package com.ruoyi.parkinglot.utils;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.io.ByteArrayOutputStream;  // 使用 java.io 包下的 ByteArrayOutputStream

public class QRCodeGenerator {

    public static ByteArrayOutputStream generateQRCodeImage(String text, int width, int height) throws Exception {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);

        return outputStream;
    }

    // 保留原方法以保持兼容性
    public static ByteArrayOutputStream generateQRCodeImage(String text) throws Exception {
        return generateQRCodeImage(text, 200, 200); // 默认尺寸
    }
}
